## ##################################
##
## Loader makefile
##
## ##################################


# attempt to auto-detect the OS
#
UNAME=$(if $(findstring _,$(shell uname -s)),$(shell uname -o),$(shell uname -s))

# OS Types
#
OSS=Msys Linux Darwin
OS=$(foreach OT, $(OSS), $(findstring $(OT), $(UNAME)))

CFLAGS += $(if $(findstring Darwin,$(OS)),-DMACOSX)
TGT    += $(if $(findstring Darwin,$(OS)),pload)
OSLIB  += $(if $(findstring Darwin,$(OS)),PLoadLib_posix.o)

CFLAGS += $(if $(findstring Linux,$(OS)),-DLINUX)
TGT    += $(if $(findstring Linux,$(OS)),pload)
OSLIB  += $(if $(findstring Linux,$(OS)),PLoadLib_posix.o)

CFLAGS += $(if $(findstring Msys,$(OS)),-DMINGW)
TGT    += $(if $(findstring Msys,$(OS)),pload.exe)
OSLIB  += $(if $(findstring Msys,$(OS)),PLoadLib_mingw.o)
LIBS   += $(if $(findstring Msys,$(OS)),-lsetupapi)
SRC    += $(if $(findstring Msys,$(OS)),enumcom.c)

CC=gcc
CFLAGS += -Wall

SRC+=PLoadLib.c PLoadMain.c
OBJ:=$(SRC:.c=.o)

all: Makefile $(OSDEP) $(OBJ) $(TGT)

%.o: %.c
	$(CC) -c $(CFLAGS) $<

$(TGT): $(OBJ) $(OSLIB)
	$(CC) $(OBJ) $(OSLIB) -o $(TGT) $(LIBS)

clean:
	rm -f *.o $(TGT)
